<?php

namespace app\api\controller;

use app\common\controller\Api;
use app\common\library\Auth;
use app\common\model\Agreement;
use app\common\model\Banner;
use app\common\model\City;
use app\common\model\Evaluation;
use app\common\model\Notice;
use app\common\model\Problem;
use app\common\model\Service;
use app\common\model\service\Order;
use app\common\model\User;
use think\Log;

/**
 * 首页接口
 */
class Index extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];
    public function ceshi()
    {
        // $this->auth->template_push(126,0,"您已成功预约，请按时到达预定地点");
        // Order::unbind_telephone('13370981991','15760185817',1);
    }
    /**
     * 首页
     *
     */
    public function index()
    {
        $banner = Banner::all();
        $notice = Notice::column('content');
        $city = City::all();
        $services = Service::where(['status' => 'normal'])->order('weigh desc')->select();
        $this->success('请求成功', compact('banner', 'notice', 'city', 'services'));
    }
    /**
     * 常见问题
     *
     */
    public function problem()
    {
        $this->success('请求成功', Problem::all());
    }
    /**
     * 协议内容
     *
     */
    public function agreement()
    {
        $params = $this->request->param();
        extract($params);
        $this->success('请求成功', Agreement::get($id));
    }
    /**
     * 问题详情
     *
     */
    public function problemInfo()
    {
        $params = $this->request->param();
        extract($params);
        $this->success('请求成功', Problem::get($id));
    }

    /**
     * 陪诊师列表
     *
     */
    public function escort()
    {
        $params = $this->request->param();
        extract($params);
        if (!isset($sort) || !$sort) {
            $sort = 'asc';
        }

        $user = new User();
        if (isset($praise) && $praise) {
            if ($praise == 1) {
                $user->where('comment_ratio', '<', 80);
            } elseif ($praise == 2) {
                $user->whereBetween('comment_ratio', [80, 89]);
            } else {
                $user->whereBetween('comment_ratio', [90, 100]);
            }
        }
        if (isset($sex) && $sex != '') {
            $user->where('gender', $sex);
        }

        if (isset($age) && !empty($age)) {
            $arr = explode(',', $age);
            $user->whereBetween('age', [$arr[0], $arr[1]]);
        }
        $user->where('city_id', (int) $city_id);
        $list = $user->where('level', 1)->paginate(10);
        $this->success('请求成功', $list);
    }
    /**
     * 评价
     *
     */
    public function evaluation()
    {
        $params = $this->request->param();
        extract($params);
        $list = Evaluation::with('user')->where('escort_id', $id)->where('evaluation', $type)->paginate(10);
        $this->success('请求成功', $list);
    }
    /**
     * 服务列表
     *
     */
    public function serviceList()
    {
        $list = Service::where(['status' => 'normal'])->order('weigh desc')->select();

        $this->success('请求成功', $list);
    }
}
